Repository navigation
Docs: the declared form first where an application writes the call, then the ad hoc one-liner - #292
Merged
Merged
Conversation
… against the definition path Adds `Defined.cs`: the queries the docs show as one-liners, written the way an application writes them, as `static readonly` definitions (`DbQuery.Text(...).Map<T>()`, `DbNonQuery.Text(...)`, `Scalar<T>()`) with the source and the values bound where they run: a list, a list on a connection you own, a write on a transaction, the first/single, new-id, page, dictionary and early-stop terminals, a pooled buffer and stream, an `AsyncReads` declaration, a declared `RowMap`, scalars and a write. `Program.cs` runs every new sample and checks what it returns (13 checks), and checks that the definition path reads what the same call on a command reads: `Scalar<int>()` over a SQLite bigint, `Scalar<long>()`, a value that does not fit, no rows and NULL for a type that takes null and for one that does not, `Scalar<string>()`, and `DbNonQuery` against `ExecuteNonQueryAsync` (10 checks). All pass: `Scalar<T>()` converts as `ExecuteScalarAsync<T>()` does. The custom conversion form (`ExecuteScalarAsync(Func<object?, T>)`) has no counterpart on the definition path, so that sample stays ad hoc. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…hen the ad hoc one-liner
The query an application runs again and again is declared once, as a `static readonly` definition with no connection (`DbQuery.Text(...).Map<T>()`), and bound where it runs; the docs now show that form first in the places that are application code, and then the same call ad hoc ("Or, simply expressive"), with nothing to declare. The places that demonstrate one feature in one line, or compare line counts, stay ad hoc.
- Declared first: the README, the Core, Channel and Dataflow package pages, Getting started (the first query, and from a connection you own), the foundation's transactions (`Using(transaction)`), Coming from Dapper (the consumer of the registered factory), Expressive commands ("Defining a query once" moves ahead of the command form, which is retitled "Building a command where you need it"), the mapping terminals (first and single, a new id, a dictionary, a page, a stream that stops early), the async buffers (a page, the data layer), Channels and Dataflow (the producer), Async reads (the opt-in is part of the declaration), Shaping rows (a map declared with its query), and What's new (the `DbQuery` section moves to the top).
- Stays ad hoc: How little code (one call against one call; a sentence says what declaring adds), the rule demonstrations of Mapping, and the rest of the feature demonstrations.
- Said plainly: a declared query has fixed text, so `AddParamIf` is a command-form call; the scalar that converts in your own way (`ExecuteScalarAsync(value => ...)`) has no declared counterpart, while `Scalar<T>()` converts as `ExecuteScalarAsync<T>()` does (checked by the samples).
Every new sample compiles in the samples project and is run and checked there; the new regions are in `Defined.cs`.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The chain style of the new declared samples and README snippets: the first call stays on the receiver's line (`await ByAuthor.Using(connectionFactory)`), and the chain goes vertical from the second call, each call on its own line; no receiver is alone on a line. A text too long for the receiver's line breaks inside the first call's argument. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The docs now show the declared form first where a reader is writing application code, and then the same call written ad hoc ("Or, simply expressive"), so both are on the page and a reader sees how little a one-off needs. A query is declared once, as a
static readonlydefinition with no connection (DbQuery.Text(...).Map<T>()), and the source and the values are bound where it runs (Using(source).AddParam(...)and a terminal). Pages that demonstrate one feature in one line, or compare line counts, stay ad hoc.Where the declared form leads
Using(transaction), then the ad hoctransaction.Command(...)AddParamIfis a command-form call (a declared query has fixed text); the scalar forms, declared firstRowMapdeclared with its queryDbQuerysection moves to the topStays ad hoc: How little code (one call against one call; one sentence says what declaring adds), the rule demonstrations of Mapping, and the other feature demonstrations.
What the samples show, and what was checked
All new samples are in
docsite/samples/Defined.cs, compile in the samples project, and are run and checked by the sample program (14 checks of what each returns).The scalar forms were checked against the definition path (10 checks, all pass):
Scalar<T>()converts asExecuteScalarAsync<T>()does (a SQLite bigint asint; a value that does not fit throwsValueMappingException; no rows andNULLarenullfor a type that takes null and throw for one that does not; strings), andDbNonQueryreturns whatExecuteNonQueryAsyncreturns.Left ad hoc, on purpose, and why
AddParamIf: the docs' only use varies the SQL text with the same condition; a declared query has fixed text. The page says so.ExecuteScalarAsync(value => ...)):Scalar<T>()has no overload for it.SequentialAccess(): a declared raw query has noSequentialAccess()and no publicExecuteReaderAsync(only the explicitIExecuteReaderone, reached by a cast of a struct). That is an API question for the owner, not something this change papers over.Checks
dotnet format styleandanalyzersat--severity inforeport nothing on all 14 projects, including the samples project; the pre-push scan is clean.staticwhere it is a class field, and a few comments (the insert that returns a value, the transaction cast, what the stream timeout bounds, who disposes the buffer). Not taken: renamingPostand the sample database's other names (the established sample database of every page), and thePooledArraydisposal point (the view is valid until its buffer is disposed, as in the existing sample).🤖 Generated with Claude Code